home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
My Sample Apps
/
OpenGLSphereDemo
/
Form1.cs
< prev
next >
Wrap
Text File
|
2005-05-03
|
2KB
|
90 lines
using System;
using System.Drawing;
using System.Windows.Forms;
using CsGL.OpenGL;
public class SphereDemo : Form
{
MyView view = new MyView();
public SphereDemo()
{
Text = "Sphere demo !";
view.Dock = DockStyle.Fill;
Controls.Add( view );
}
public static void Main()
{
SphereDemo di = new SphereDemo();
Application.Run( di );
}
}
class MyView : OpenGLControl
{
public override void glDraw()
{
GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
GL.glShadeModel( GL.GL_SMOOTH );
/*GL.glBegin( GL.GL_QUADS );
GL.glColor3f(1,1,1);
//GL.glVertex3i( 100, 50, 0);
GL.glVertex3i( -10, -10, -20);
GL.glColor3f(1,0,1);
//GL.glVertex3i( 100, 130, 0 );
GL.glVertex3i( -10, 10, -30);
GL.glColor3f(1,1,0);
//GL.glVertex3i( 150, 130, 0 );
GL.glVertex3i( 10, 10, -5);
GL.glColor3f(0,1,1);
//GL.glVertex3i( 150, 50, 0 );
GL.glVertex3i( 10, -10, -3);
GL.glEnd();*/
CsGL.OpenGL.GLUquadric q = GL.gluNewQuadric();
int radius;
radius = 1;
GL.glTranslated(-2,-2,-2);
GL.gluQuadricDrawStyle(q,GL.GLU_FILL);
GL.glColor3f(1,1,1);
GL.gluSphere(q, radius, 20, 20);
GL.glTranslated(2,2,2);
GL.glTranslated(2,-2,-2);
GL.gluQuadricDrawStyle(q,GL.GLU_LINE);
GL.glColor3f(1,0,0);
GL.gluSphere(q, radius, 20, 20);
GL.glTranslated(-2,2,2);
GL.glTranslated(-2,2,-2);
GL.gluQuadricDrawStyle(q,GL.GLU_SILHOUETTE);
GL.glColor3f(0,1,0);
GL.gluSphere(q, radius, 20, 20);
GL.glTranslated(2,-2,2);
GL.glTranslated(2,2,-2);
GL.gluQuadricDrawStyle(q,GL.GLU_POINT);
GL.glColor3f(0,0,1);
GL.gluSphere(q, radius, 20, 20);
GL.glTranslated(-2,-2,2);
GL.glFlush();
}
protected override void InitGLContext()
{
GL.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
GL.glEnable( GL.GL_DEPTH_TEST);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
//GL.glOrtho( -20,20, -20,20, 0,1000);
GL.gluPerspective(90,1, 0.1,1000);
GL.glMatrixMode(GL.GL_MODELVIEW );
GL.glLoadIdentity();
GL.gluLookAt(0,0,3, 0,0,0, 0,1,0);
}
}